function CharacterSelector(options) 
{
	// Create a new input element
	var element = $.create('input', {"class":"autocomplete"});
	var selected = null;
	
	// Store script and parameters
	var script = (options.script) ? options.script : null;
	var params = (options.params) ? options.params : {};
	
	// Attach id and class if needed
	if (options.id) $(element).attr("id", options.id);
	if (options.class) $(element).attr("class", options.class);
	
	// Self reference (is there any other way to do this?)
    var self = this; 

	// Setup the element to setup autocompletion on focus
	$(element).focus( function() {
    	$(this).autocomplete({ ajax_get: getCharacterList,
    						   callback: onSelect,
    						   minchars: 1 });
    });
    
    function onSelect(suggest) 
    {	
    	selected = suggest.id;
    }
	
	function getCharacterList(key, cont) 
	{
		var script_name = script;
   		var script_params = params;
   		script_params.q = key;
   		
   		$.post(	script_name,
   				script_params,
         		function(response) { 
         			if (response.status != 200) {
						alert(response.message);
					}
					
         			var result = [];
         			
					$.each( response.data, function(i, char) {
      					result.push({ id: char.id , 
      								  value: char.name,
      								  info: char.info });
    				});
    				
	           		cont(result); 
	           		
	       		},
	       		'json');
	}
	
	this.setParam = function(name, value) 
	{
		params[name] = value;
	}
	
	//
	this.getElement = function()
	{
		return element;
	}
	
	this.getId = function() 
	{
		return selected;
	}
}